#define FREEGLUT_STATIC
#include <GLTools.h>            // OpenGL toolkit
#include <GL/glut.h>            // Windows FreeGlut equivalent

GLuint shader;

void ChangeSize(int w, int h) {
    glViewport(0, 0, w, h);
} 

void SetupRC() {
    glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
    shader = gltLoadShaderPairWithAttributes("cw1_thru_shader.vp", "cw1_thru_shader.fp",
            2, GLT_ATTRIBUTE_VERTEX, "vVertex", GLT_ATTRIBUTE_COLOR, "vColor");
    fprintf(stdout, "GLT_ATTRIBUTE_VERTEX : %d\nGLT_ATTRIBUTE_COLOR : %d \n",
            GLT_ATTRIBUTE_VERTEX, GLT_ATTRIBUTE_COLOR);
}

void RenderScene(void) {
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
    glUseProgram(shader);
    glBegin(GL_TRIANGLES);
    glVertexAttrib3f(GLT_ATTRIBUTE_COLOR, 1.0, 0.0, 0.0);
    glVertex3f(-0.5f, -0.5f, 2.0f);
    glVertex3f(0.5f, 0.0f, 1.0);
    glVertex3f(0.0f, 0.5f, -1.0f);
    glEnd();
    glutSwapBuffers();
}

int main(int argc, char* argv[]) {
	glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH | GLUT_STENCIL);
    glutInitWindowSize(800, 600);
    glutCreateWindow("Zadanie 1");
    glutReshapeFunc(ChangeSize);
    glutDisplayFunc(RenderScene);
    GLenum err = glewInit();
    if (GLEW_OK != err) {
        fprintf(stderr, "GLEW Error: %s\n", glewGetErrorString(err));
        return 1;
    }
    SetupRC();
    glutMainLoop();
    return 0;
}
